﻿using System;

namespace DesignPattern.com.state.scene {
    public class SceneController {

        //游戏加载标志
        public static bool loadFlag=true;
        
        private SceneState state;

        private bool beginFlag;

        public void setState(SceneState state, string sceneName){
            
            beginFlag = false;

            loadScene(sceneName);

            if (this.state != null){
                this.state.stateEnd();
            }
            this.state = state;
        }

        private void loadScene(string sceneName){
            Console.WriteLine("Application.LoadLevel({0})",sceneName);
        }

        public void stateUpdate(){
            Console.WriteLine("SceneController-stateUpdate()");
            Console.WriteLine("judg Application.isLoadingLeve="+loadFlag);

            if (loadFlag){
                Console.WriteLine("loadflag==true and will return");
                return;
            }
            
            if (state != null && !beginFlag){
                state.stateBegin();
                beginFlag = true;
            }

            if (state != null && beginFlag){
                state.stateUpdate();
            }
        }
    }
}